/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
 struct ListNode* successor;
 struct ListNode* reverse(struct ListNode* N,int n)
{
if (n==1)
{
    successor=N->next;                 //防止边界情况时把指针断开
    return N;
    }
    struct ListNode* last=reverse(N->next,n-1);
    N->next->next=N;
    N->next=successor;                      //链接新节点时断开旧节点
    return last;
}
struct ListNode* reverseBetween(struct ListNode* head, int left, int right) {
    if(left==1)
    {
        return reverse(head,right);
    }
    head->next=reverseBetween(head->next,left-1,right-1);  //递归找到要翻转的链表
    return head;
    
    
}